package com.appleyk.component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>越努力，越幸运</p>
 * 自定义web servlet组件
 * @author appleyk
 * @version V.0.1.1
 * @blob https://blog.csdn.net/appleyk
 * @date created on  9:58 下午 2021/2/27
 */
public class MyServlet extends HttpServlet {

    // servlet只有在第一次被调用时，才会初始化
    @Override
    public void init() throws ServletException {
        System.out.println("MyServlet init() method is called.");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 要想进入servlet的goGet方法，必须要经过filter的doFilter方法，在那里对request和response进行放行
        System.out.println("MyServlet doGet method is called.");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("MyServlet doPost method is called.");
    }
}
